package com.bazaaroid.server.gae.core.persistence.model.partner;

import java.util.HashSet;
import java.util.Set;

import javax.jdo.annotations.IdentityType;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;

import com.bazaaroid.server.gae.core.persistence.model.AbstractModel;
import com.google.appengine.api.datastore.Key;

@SuppressWarnings("serial")
@PersistenceCapable(identityType = IdentityType.APPLICATION, detachable ="true")
public class Category extends AbstractModel {

	@Persistent
	private String name;
	@Persistent
	private Set<Key> products = new HashSet<Key>();

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public void setProducts(Set<Key> products) {
		this.products = products;
	}

	public Set<Key> getProducts() {
		return products;
	}

	public void addProduct(Product product) {
	    products.add(product.getKey());
	    product.getCategories().add(getKey());
	}

	public void removeProduct(Product product) {
		products.remove(product.getKey());
		product.getCategories().remove(getKey());
	}

}
